package com.xxx.video.mine.adapters;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.xxx.video.R;
import com.xxx.video.commen.adapters.BaseRecycleViewAdapter;
import com.xxx.video.commen.adapters.BaseViewHolder;
import com.xxx.video.commen.utils.CountUtils;
import com.xxx.video.commen.utils.DimensionUtil;
import com.xxx.video.commen.utils.ResourcesUtils;
import com.xxx.video.commen.utils.StringUtils;
import com.xxx.video.mine.beans.CommentListBean;

import butterknife.BindView;

public class CommentManagementListAdapter extends BaseRecycleViewAdapter<CommentListBean.ListBean, CommentManagementListAdapter.MyHolder> {


    public CommentManagementListAdapter(@NonNull Context context) {
        super(context);
    }

    @Override
    public MyHolder onCreateDefaultViewHolder(View view, int viewType) {
        return new MyHolder(view);
    }

    @Override
    public int getItemLayout(int viewType) {
        return R.layout.item_comment_management_list;
    }

    class MyHolder extends BaseViewHolder {
        @BindView(R.id.iv_item_comment_management_list_avatar)
        ImageView ivItemCommentManagementListAvatar;
        @BindView(R.id.tv_item_comment_management_list_name)
        TextView tvItemCommentManagementListName;
        @BindView(R.id.tv_item_comment_management_list_comment_content)
        TextView tvItemCommentManagementListCommentContent;
        @BindView(R.id.iv_item_comment_management_list_video_cover)
        ImageView ivItemCommentManagementListVideoCover;
        @BindView(R.id.tv_item_comment_management_list_video_time)
        TextView tvItemCommentManagementListVideoTime;
        @BindView(R.id.tv_item_comment_management_list_video_title)
        TextView tvItemCommentManagementListVideoTitle;
        @BindView(R.id.tv_item_comment_management_list_video_play_count)
        TextView tvItemCommentManagementListVideoPlayCount;
        @BindView(R.id.tv_item_comment_management_list_video_comment_count)
        TextView tvItemCommentManagementListVideoCommentCount;
        @BindView(R.id.tv_item_comment_management_list_video_date)
        TextView tvItemCommentManagementListVideoDate;

        public MyHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void setData2View(int position) {
            CommentListBean.ListBean listBean = getItem(position);
            /*
             * avatar
             */
            Glide.with(context).load(ResourcesUtils.getInstance().getImagePath(listBean.fUsePicurl))
                    .apply(new RequestOptions()
                            .error(R.drawable.icon_default_avatar)
                            .placeholder(R.drawable.icon_default_avatar)
                            .circleCrop())
                            .into(ivItemCommentManagementListAvatar);
            /*
             * name
             */
            tvItemCommentManagementListName.setText(StringUtils.getInstance().getNotEmptyMsg(listBean.fUserName));
            /*
             * comment
             */
            tvItemCommentManagementListCommentContent.setText(StringUtils.getInstance().getNotEmptyMsg(listBean.fComment));
            /*
             * cover
             */
            Glide.with(context).load(ResourcesUtils.getInstance().getImagePath(listBean.fPicurl))
                    .apply(new RequestOptions()
                            .error(R.drawable.bg_place_holder_nine_five)
                            .placeholder(R.drawable.bg_place_holder_nine_five)
                            .transform(new CenterCrop(), new RoundedCorners(DimensionUtil.dpToPx(5))))
                    .into(ivItemCommentManagementListVideoCover);
            /*
             * time
             */
            tvItemCommentManagementListVideoTime.setVisibility(View.GONE);
            /*
             * title
             */
            tvItemCommentManagementListVideoTitle.setText(StringUtils.getInstance().getNotEmptyMsg(listBean.fContentName));
            /*
             * play count
             */
            tvItemCommentManagementListVideoPlayCount.setText(CountUtils.getInstance().getCount(listBean.fPlayTimes));
            /*
             *comment count
             */
            tvItemCommentManagementListVideoCommentCount.setText(CountUtils.getInstance().getCount(listBean.fCommentTimes));
            /*
             * date
             */
            tvItemCommentManagementListVideoDate.setText(StringUtils.getInstance().getNotEmptyMsg(listBean.fCreateTime));
        }
    }
}
